package com.miku.blog.controller;

import com.miku.blog.annotation.SystemLog;
import com.miku.blog.domain.Menu;
import com.miku.blog.domain.pojo.ResponseResult;
import com.miku.blog.service.MenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * @author shkstart
 * @create ${}YEAR-05-25 19:16
 */
@Api(tags = "后台管理系统[菜单]")
@RequestMapping("/admin")
@RestController
public class MenusController {

    @Autowired
    private MenuService menuService;

    @SystemLog(notes = "获取用户菜单列表{后台管理系统}")
    @ApiOperation(value = "获取用户菜单列表接口",notes = "查询当前所登录的用户下的菜单列表")
    @GetMapping("/user/menus")
    public ResponseResult userMenus(){
        return menuService.userMenus();
    }

    @SystemLog(notes = "获取角色菜单列表{后台管理系统}")
    @ApiOperation(value = "获取角色菜单列表接口",notes = "获取菜单列表{ 二级列表 } (用于角色管理模块)")
    @GetMapping("/role/menus")
    public ResponseResult getMenus(){
        return menuService.getMenus();
    }

    @SystemLog(notes = "获取菜单列表{后台管理系统}")
    @ApiOperation(value = "获取菜单列表接口",notes = "获取菜单列表(用于菜单管理模块)")
    @GetMapping("/menus")
    public ResponseResult getMenuList(@RequestParam(value = "keywords",required = false) String keywords){
        return menuService.getMenuList(keywords);
    }

    @SystemLog(notes = "显示/隐藏菜单{后台管理系统}")
    @ApiOperation(value = "显示/隐藏菜单接口")
    @PutMapping("/menus/hidden/{menuId}")
    public ResponseResult isHidden(@PathVariable("menuId") Integer menuId,
                                   @RequestParam("isHidden") Integer isHidden)
    {
        return menuService.isHidden(menuId,isHidden);
    }


    @SystemLog(notes = "添加或修改菜单{后台管理系统}")
    @ApiOperation(value = "添加或修改菜单接口")
    @PostMapping("/menus")
    public ResponseResult updateMenu(@RequestBody Menu menu){
        return menuService.updateMenu(menu);
    }


    @SystemLog(notes = "删除(物理)菜单{后台管理系统}")
    @ApiOperation(value = "删除(物理)菜单接口")
    @DeleteMapping("/menus/{menuId}")
    public ResponseResult deleteMenu(@PathVariable("menuId") Integer menuId){
        return menuService.deleteMenu(menuId);
    }

}
